import {
  Injectable
}
from 'angular2/core';
import {
  HmrState
}
from 'angular2-hmr';
import {
  Http
}
from 'angular2/http';
import {Util} from './app.util.service';

@
Injectable()
export class AppState {
  // HmrState uis used by HMR to track the any state during reloading
  @
  HmrState() _state = {};

  constructor() {

  }

  // already return a clone of the current state
  get state() {
      return this._state = this._clone(this._state);
    }
    // never allow mutation
  set state(value) {
    throw new Error('do not mutate the `.state` directly');
  }


  get(prop ? : any) {
    // use our state getter for the clone
    const state = this.state;
    return state[prop] || state;
  }

  set(prop: string, value: any) {
    // internally mutate our state
    return this._state[prop] = value;
  }


  _clone(object) {
    // simple object clone
    return JSON.parse(JSON.stringify(object));
  }
}

@
Injectable()
export class Bilibili {
  constructor(public util:Util){
    
  }
  
  getVideos(url:string,cb:(result:any)=>void){
    var aid = this.util.getAV(url);
    if(aid!==0){
      this.util.getVideos(aid,result => {
        console.log(result);
        cb(result);
      });
    }
  }
}
